home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 February / EnigmA AMIGA RUN 34 (1999)(G.R. Edizioni)(IT)[!][issue 1999-02].iso / www / amitrix / trans.lha / translate / translate.awebrx < prev    next >
Text File  |  1998-06-11  |  6KB  |  230 lines

  1. /*
  2. $VER: translate.awebrx 1.4
  3. 11 Jun 1998
  4. Translation functions for AWEB-II.
  5. By William H. M. Parker <bill@amitrix.com>
  6. All Rights Reserved DO NOT DISTRIBUTE
  7. */
  8.  
  9. options results
  10. sel=''
  11. if ~show('L','rexxsupport.library') then
  12. if ~addlib('rexxsupport.library',0,-30,0) then
  13. exit(20)
  14. ports = show('P')
  15. parse var ports dummy 'AWEB.' portnr .
  16. address value 'AWEB.' || portnr
  17. 'GET ACTIVEPORT'
  18. awebhost = result
  19. address value awebhost
  20. parse source prog_type result_flag called resolved ext host .
  21. c_dir=path(called)
  22. if ~showlist(H,'AWNPIPE') then address command 'mount >nil: awnpipe:'
  23.  
  24. 'get selection var sel'
  25. sel=translate(sel,' ','a0'x)
  26. 'get url var url'
  27.  
  28. parse arg mode opt .
  29. if mode='u' then do
  30.   parse arg . url mode opt
  31.   sel=''
  32.   url=strip(url,'B','"')
  33. end
  34. if left(mode,3)='ask' then do
  35.   temp=mode
  36.   mode=opt
  37.   opt=temp
  38. end
  39.  
  40. if sel='' then do
  41.   if left(opt,3)~='ask' then reqm=2
  42.   else do
  43.     reqm=reqch('"URL 'url'*NNo text selected.*NWhat would you like to translate ?" "Read _Docs|_URL|_ClipBoard|Co_n:|_Quit"')
  44.     if reqm=1 then do
  45.       'Open file://localhost/'c_dir'translate.html'
  46.       exit
  47.     end
  48.     if reqm=0 then exit
  49.     if reqm=3 then do
  50.       reqm=4
  51.       call open(cb,'awnpipe:clip/f/v','R')
  52.       sel=readch(cb,8000)
  53.       call close(cb)
  54.     end
  55.     else if reqm=4 then reqm=5
  56.   end
  57. end
  58.  
  59. if length(mode)~=5 | substr(mode,3,1)~='_' then do
  60.   if mode='' then do
  61.     v1='unset'
  62.     mode=reqch('"Choose translation type.*NItaliano English Deutsch Português Français Español" "En>Fr|En>De|En>It|En>Pt|En>Es|Fr>En|De>En|It>En|Es>En|Pt>En|_Quit"')
  63.   end
  64.   else do
  65.     v1='invalid'
  66.     mode=reqch('"Configured translation type incorect*NChoose translation type.*NItaliano English Deutsch Português Français Español" "En>Fr|En>De|En>It|En>Pt|En>Es|Fr>En|De>En|It>En|Es>En|Pt>En|_Quit"')
  67.   end
  68.   if mode=1 then mode='en_fr'
  69.   if mode=2 then mode='en_de'
  70.   if mode=3 then mode='en_it'
  71.   if mode=4 then mode='en_pt'
  72.   if mode=5 then mode='en_es'
  73.   if mode=6 then mode='fr_en'
  74.   if mode=7 then mode='de_en'
  75.   if mode=8 then mode='it_en'
  76.   if mode=9 then mode='es_en'
  77.   if mode=10 then mode='pt_en'
  78.   if mode=0 then exit
  79. end
  80. v1=mode
  81. if right(mode,2)='it' then v2='Italiano:'
  82. if right(mode,2)='en' then v2='English:'
  83. if right(mode,2)='de' then v2='Deutsch:'
  84. if right(mode,2)='pt' then v2='Português:'
  85. if right(mode,2)='fr' then v2='Français:'
  86. if right(mode,2)='es' then v2='Español:'
  87.  
  88. if reqm=2 then do
  89.   'open "http://babelfish.altavista.digital.com/cgi-bin/translate?" post="doit=done&urltext='url'&languagepair='mode'" reload'
  90.   exit
  91. end
  92.  
  93. if left(opt,4)='aska' & reqm~=4 &reqm~=5 then do
  94.   reqm=reqch('"URL 'url'*NWhat would you like to translate ?" "Read _Docs|_URL|_AWeb Text|_ClipBoard|Co_n:|_Quit"')
  95.   if reqm=0 then exit
  96.   if reqm=1 then do
  97.     'Open file://localhost/'c_dir'translate.html'
  98.     exit
  99.   end
  100.   if reqm=2 then do
  101.     'open "http://babelfish.altavista.digital.com/cgi-bin/translate?" post="doit=done&urltext='url'&languagepair='mode'" reload'
  102.     exit
  103.   end
  104.   if reqm=4 then do
  105.     call open(cb,'awnpipe:clip/f/v','R')
  106.     sel=readch(cb,8000)
  107.     call close(cb)
  108.   end
  109. end
  110. if reqm=5 then do
  111.   call open(con,'con://// 'mode'  Enter text to be translated/close/screen aweb')
  112.   do while ~eof(con)
  113.    call  writeln(con,e2i(readln(con)))
  114.   end
  115.   exit
  116. end
  117.  
  118. if reqm~=4 then 'CLEARSELECTION'
  119. call testtcp()
  120. tt=e2i(sel)
  121.  
  122. if reqm=4 then do
  123.   call open(cb,'awnpipe:clip/f/c','W')
  124.   call writech(cb,tt)
  125.   call close(cb)
  126. end
  127.  
  128. t2=''
  129. do while tt~=''
  130.   parse var tt t1 '<P>' tt
  131.   t2=t2||t1
  132. end
  133. tt=t2
  134. parse var tt t2 '0a'x tt
  135. do while tt~=''
  136.   parse var tt t1 '0a'x tt
  137.   if tt~='' then t2=t2||'*N't1
  138.   else t2=t2||t1
  139. end
  140. t2=translate(t2,"'",'"')
  141. prt=reqch('"'t2'" "_ok|_save|_print"')
  142. if prt=0 then do
  143.   call open(p,'prt:','W')
  144.   call writeln(p,t2)
  145.   call close(p)
  146. end
  147. if prt=2 then do
  148.   spath=getclip('translatedir')
  149.   if spath='' then 'getcfg savepath var spath'
  150.   'Requestfile "Translator Save" file "'spath'.trans"  savemode'
  151.   if rc=5 then exit
  152.   savename=result
  153.   call open(s,savename,'W')
  154.   call writeln(s,t2)
  155.   call writeln(s,v1)
  156.   call writeln(s,sel)
  157.   call close(s)
  158.   call setclip('translatedir',path(savename))
  159. end
  160.  
  161. exit
  162.  
  163. e2i:
  164. procedure expose v2 v1
  165. if strip(arg(1))='' then return('')
  166. w=translate(arg(1),' ','+')
  167. t1='doit=done&urltext='w'&languagepair='v1
  168. t2=length(t1)
  169. t2='Content-Length: 't2
  170. if ~ open(net,'tcp:babelfish.altavista.digital.com/80') then call reqchx('"Unable to access babelfish.altavista.digital.com*nRetrys later"')
  171.  
  172. call writeln(net,"POST /cgi-bin/translate? HTTP/1.0")
  173. call writeln(net,"User-Agent: MSIE/4.0; (Spoofed by billybob (1.0 beta))")
  174. call writeln(net,"Accept: */*;q=1")
  175. call writeln(net,"babelfish.altavista.digital.com")
  176. call writeln(net,t2)
  177. call writeln(net,"Content-Type: application/x-www-form-urlencoded")
  178. call writeln(net,"")
  179. call writeln(net,t1)
  180. call writeln(net,"")
  181. def=''
  182. do while ~eof(net)
  183.   if length(def)< 54000 then def=def||readch(net,10000)
  184. end
  185. call close(net)
  186. parse var def (v2). '<td align="left">' d1 'helvetica">'d1 '<br><br></font'
  187. call open(fh,'awnpipe:dec/u/f','W')
  188. call writech(fh,d1)
  189. call close(fh)
  190. call open(fh,'awnpipe:dec','R')
  191. txt=readch(fh,64000)
  192. call close(fh)
  193. if txt='' then do
  194.   if index(def,'Server Error')>0 then reqchx('"Server Error*n babelfish.altavista.digital may be down."')
  195.   reqchx('Not Found')
  196. end
  197. else do
  198.   return(strip(txt,'B','0a'x))
  199. end
  200.  
  201. reqch:
  202. parse arg reqchd
  203. Request '" Translator ' v1 '"' reqchd
  204. if rc=5 then return(0)
  205. reqchd=result
  206. return(reqchd)
  207.  
  208. reqchx:
  209. parse arg reqchd
  210. call reqch(reqchd'"_ok"')
  211. exit
  212.  
  213. path:
  214. parse arg pathf
  215. dir_pos = max(lastpos('/',pathf),lastpos(':',pathf))
  216. if dir_pos > 0 then return(left(pathf,dir_pos))
  217. else return('')
  218.  
  219. testtcp:
  220. call pragma(w,n)
  221. if ~showlist(H,'TCP') then do
  222.   t= reqch(' "Unable to attemp Host Connection!*n Translate requires a valid TCP: device.*nConfiguration changes will not solve this." "_help|_sorry"')
  223.   if t=1 then do
  224.     'Open file://localhost/'c_dir'translate.html'
  225.   end
  226.   exit
  227. end
  228. return
  229.  
  230.